<?php use_helper('Pagination') ?>
<?php slot('coursesNav', 'active') ?>
<div class="courses" id="wrapper">
	<?php include_partial('global/systemMessages') ?>
	<div id="content">
		<div id="main">
			<div class="main-heading">
				<form method="get" action="<?php echo url_for('courses/index')?>" id="select-semester">
					<fieldset>
						<label>Network</label>
						<select id="network" name="network_id">
								<option value="">All</option>
							<?php foreach($networks as $id => $network): ?>
								<option value="<?php echo $id ?>" <?php echo $id == $network_id ? 'selected="selected"' : ''?>>
									<?php echo $network ?>
								</option>
							<?php endforeach ?>
						</select>
						<label>Semester</label>
						<select id="semester" name="semester_id">
								<option value="">All</option>
            				<?php foreach($semesters as $semester): ?>
            					<option value="<?php echo $semester->getId() ?>" <?php echo $semester->getId() == $semester_id ? 'selected="selected"' : ''?>>
            						<?php echo $semester->getTerm() ?> <?php echo $semester->getYear('Y') ?>
            					</option>
            				<?php endforeach ?>
                        </select><br>
						<label>Subject</label>
						<select id="subject" name="subject_id">
								<option value="">All</option>
							<?php foreach($subjects as $subject): ?>
								<option value="<?php echo $subject->getId(); ?>" <?php echo $subject->getId() == $subject_id ? 'selected="selected"' : ''?>>
									<?php echo $subject ?>
								</option>
							<?php endforeach ?>
						</select>
						&nbsp;
						<label><input type="submit" value="Go" /></label>
						
					</fieldset>
				</form>
				<h1>All  Classes</h1>
			</div>
			<ul class="filter-links">
				<li class="current">
					<a href="#">Most Popular</a>
				</li>
				<!--<li><a href="#">Most Recent</a></li>-->
			</ul>
			<ul class="courses-list">
				<?php foreach($courses as $course): ?>
				<li>
					<h3>
						<?php echo $course->getSubject() != null ? $course->getSubject()->getName() .":" : '' ?>
						<?php echo link_to($course->getName(), 'courses/show?id='.$course->getId()) ?>
					</h3>
					<div class="details">
						<p class="related-users">
							<strong>Instructor: </strong>
							<?php echo $course->getInstructorName() ?>
						</p>
						<!--<p class="related-users"><strong>Note Takers: </strong><a href="#">Zana Rosa</a>, <a href="#">FauxNeme</a>, <a href="#">Sagitarius</a>, <a href="#">15 more...</a></p>-->
						<p><?php echo $course->getDescription() ?></p>
						<p class="stars two">
							<span>3 stars</span>
							<a href="#">3<span> comments</span></a>
						</p>
					</div>
				</li>
				<?php endforeach ?>
				
				<?php if($courses_pager->haveToPaginate()): ?>
					<li class="last">
						<p class="view-all" style="text-align: right;">
				<?php
					$subjectParam = $sf_request->getParameter('subject_id') ? ("?subject_id=".$sf_request->getParameter('subject_id')) : "";
				?>
							<?php echo pager_navigation($courses_pager, 'courses/index'.$subjectParam) ?>
						</p>
					</li>
				<?php endif ?>
				<!-- 
	            <li class="last">
					<p class="view-all"><a href="#">View all Harvard Courses &raquo;</a></p>
            	</li>
            	-->
			</ul>
		</div>
		<!-- MAIN -->
		<div id="sidebar">
			<div class="module study-groups">
				<h3 class="gradient light">
					<?php echo link_to('Add a Course', 'courses/new') ?>
					Still Searching?
				</h3>
			</div>
			<div class="module link-list">
				<h3 class="gradient dark">Popular Course Subjects</h3>
				<div class="inner">
					<ul>
						<?php foreach($subjects as $subject): 
							$count = NotePeer::countForSubjectId($subject->getId());
							//$count = CoursePeer::countForSubjectId($subject->getId(),$network_id);
							if($count != 0){
								echo "<li>";
								echo link_to($subject->getName()." (".$count." notes)", 'courses/index?subject_id='.$subject->getId());						
								echo "</li>";
							}						
							endforeach ?>
					</ul>
					<p align='right'><?php echo link_to('View All', 'subjects/index?network_id='.$network_id) ?></p>
				</div>
			</div>

		</div>

		
		
	</div>


</div>
